<template>
<div class="bh-dialog__wrapper" v-show="visible">
	<div class="bh-dialog" :style="style">
		<div class="bh-dialog__header">
			<span class="bh-dialog__title">{{title}}</span>
			<button class="bh-dialog__headerbtn" @click="handleClose">
				<bh-icon name='close'></bh-icon>
			</button>
		</div>
		<div class="bh-dialog__body">
			<slot></slot>
		</div>
		<div class="bh-dialog__footer">
			<slot name="footer"></slot>
		</div>
	</div>
</div>
</template>

<script>
export default {
	name: 'bh-dialog',
	props: {
		type: {
			type: String,
			default: 'info',
		},
		title: {
			type: String,
			default: '提示',
		},
		width: [Number,String],
		visible: {
			type: Boolean,
			default: false,
		}
	},
	data() {
		return {
			closed: false,
		}
	},
	watch: {
		visible(val) {
			console.log(val);
			if(val) {
				console.log(11);
			}else {
				console.log(22);
			}
		},
	},
	methods: {
		close() {
			this.$emit('close');
		},
		hide() {
			//if (cancel !== false) {
				this.$emit('update:visible', false);
				this.$emit('close');
				this.closed = true;
			//}
		},
		handleClose() {
			if (typeof this.beforeClose === 'function') {
				this.beforeClose(this.hide);
			} else {
				this.hide();
			}
		},
	},
	computed: {
		style() {
			let style = {};
			if (this.width) {
				style.width = this.width;
			}
			return style;
		},
	},
}
</script>
